<template>
	<view>

		<view class="example">

			<!-- 展示不同的排列方式 -->
			<uni-forms ref="baseForm" :modelValue="baseData" :rules="rules">
				<uni-forms-item label="标签" required name="EnCode">
					<uni-easyinput v-model="baseData.EnCode" placeholder="请输入标签" focus="focus" @confirm="dosearch" />
				</uni-forms-item>

				<uni-forms-item label="仓库" required name="WarehouseId">
					<uni-data-select disabled v-model="baseData.WarehouseId" :localdata="Warehouse"></uni-data-select>


				</uni-forms-item>
				<uni-forms-item label="存储区" required name="AreaId">
					<uni-data-select disabled v-model="baseData.AreaId" :localdata="Area"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="货架" required name="ShelvesId">
					<uni-data-select disabled v-model="baseData.ShelvesId" :localdata="Shelves"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="库位" required name="GoodsId">
					<uni-data-select disabled v-model="baseData.GoodsId" :localdata="Goods"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="装载区" name="LoadAreaCode">
					<uni-easyinput v-model="baseData.LoadAreaCode" placeholder="请输入装载区" />
				</uni-forms-item>

				<uni-forms-item label="托盘" name="PalletCode">
					<uni-easyinput disabled v-model="baseData.PalletCode" placeholder="请输入托盘" />
				</uni-forms-item>
				<uni-forms-item label="编码" required name="ProductCode">
					<uni-easyinput disabled v-model="baseData.ProductCode" placeholder="请输入产品编码" />
				</uni-forms-item>
				<uni-forms-item label="名称" required name="ProductName">
					<uni-easyinput disabled v-model="baseData.ProductName" placeholder="请输入产品名称" />
				</uni-forms-item>
				<uni-forms-item label="规格" required name="Cinvstd">
					<uni-easyinput disabled v-model="baseData.Cinvstd" placeholder="请输入产品规格" />
				</uni-forms-item>

				<uni-forms-item label="批号" required name="Batch">
					<uni-easyinput disabled v-model="baseData.Batch" placeholder="请输入批号" />
				</uni-forms-item>
				<uni-forms-item label="数量" required name="Number">
					<uni-easyinput disabled v-model="baseData.Number" placeholder="请输入数量" />
				</uni-forms-item>
				<uni-forms-item label="单位" required name="CinvmUnit">
					<uni-easyinput disabled v-model="baseData.CinvmUnit" placeholder="请输入单位" />
				</uni-forms-item>
				<uni-forms-item label="辅助数量" name="Number1">
					<uni-easyinput disabled v-model="baseData.Number1" placeholder="请输入辅助数量" />
				</uni-forms-item>
				<uni-forms-item label="辅助单位" name="CinvmUnit1">
					<uni-easyinput disabled v-model="baseData.CinvmUnit1" placeholder="请输入辅助单位" />
				</uni-forms-item>

				</uni-forms-item>
				<uni-forms-item label="备注">
					<uni-easyinput disabled v-model="baseData.Description" placeholder="请输入备注" />
				</uni-forms-item>
			</uni-forms>
			<button type="primary" @click="submit('baseForm')">保存</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseData: {
					HeadId: '',
					LoadAreaCode: '',
					EnCode: '',
					PalletCode: '',
					ProductCode: '',
					ProductName: '',
					Cinvstd: '',
					Batch: '',
					Number: '',
					Number1: '',
					CinvmUnit1: '',
					CinvmUnit: '',
					WarehouseId: '',
					Warehouse: '',
					AreaId: '',
					Area: '',
					ShelvesId: '',
					Shelves: '',
					GoodsId: '',
					Goods: '',
					Description: '',
					PdaAuditUserName: this.$store.state.userInfo.RealName,
					PdaAuditUserId: this.$store.state.userInfo.RealId,

					Pda: true,
				},
				Goods: [],
				Shelves: [],
				Area: [],
				Warehouse: [],
				focus: false,
				Id: '',
				WarehouseId: '',
				hid: '',
				rules: {
					// 对name字段进行必填验证
					EnCode: {
						// name 字段的校验规则
						rules: [
							// 校验 name 不能为空
							{
								required: true,
								errorMessage: '请填写标签编码',
							},

						],

					},

				},

			}
		},
		onLoad(param) {

			this.hid = param.hid;
			this.WarehouseId = param.WarehouseId;
			this.baseData.HeadId = param.hid;
			this.$api.Request({
					url: "/api/BasicData/GetWarehouse",
					method: 'GET',
					data: {},
				}).then((res) => {

					res.forEach(item => {

						this.Warehouse.push({
							value: item.Id,
							text: item.WarehouseName
						})

					});

				}),
				this.$api.Request({
					url: "/api/BasicData/GetArea",
					method: 'GET',
					data: {},
				}).then((res) => {

					res.forEach(item => {

						this.Area.push({
							value: item.Id,
							text: item.AreaName
						})

					});

				}),
				this.$api.Request({
					url: "/api/BasicData/GetShelves",
					method: 'GET',
					data: {},
				}).then((res) => {

					res.forEach(item => {

						this.Shelves.push({
							value: item.Id,
							text: item.ShelvesName
						})

					});

				}),
				this.$api.Request({
					url: "/api/BasicData/GetGoods",
					method: 'GET',
					data: {},
				}).then((res) => {

					res.forEach(item => {

						this.Goods.push({
							value: item.Id,
							text: item.EnCode
						})

					});

				})
		},

		methods: {
			dosearch() {

				this.$api.Request({
					url: "/api/Output/GetInputbodyListPda?WarehouseId=" + this.WarehouseId + "&keyword=" + this
						.baseData.EnCode,
					method: 'GET',

				}).then((res) => {

					if (res.length == 0) {

						uni.showToast({
							title: `记录不存在`,

						})
						this.focus = true;
					} else {
						this.Id = res[0].Id;

						this.baseData.ProductCode = res[0].ProductCode;
						this.baseData.ProductName = res[0].ProductName;
						this.baseData.Cinvstd = res[0].Cinvstd;
						this.baseData.CinvmUnit = res[0].CinvmUnit;
						this.baseData.CinvmUnit1 = res[0].CinvmUnit1;
						this.baseData.Batch = res[0].Batch;
						this.baseData.Number = res[0].Number;
						this.baseData.Number1 = res[0].Number1;
						this.baseData.Description = res[0].Description;
						this.baseData.WarehouseId = res[0].WarehouseId;
						this.baseData.AreaId = res[0].AreaId;
						this.baseData.ShelvesId = res[0].ShelvesId;
						this.baseData.GoodsId = res[0].GoodsId;
						this.baseData.PalletCode = res[0].PalletCode;
					}

				})
			},
			submit(ref) {

				this.$refs[ref].validate().then(res => {
					this.$api.Request({
						url: "/api/Output/SubmitFormbody?keyValue=" + this.Id + '&hid=' + this.hid +
							"&wid=" + this.WarehouseId,
						method: 'POST',
						data: this.baseData,
					}).then((res) => {
						if (res.state == 'success') {
							uni.showToast({
								title: `提交成功`,

							})
							setTimeout(() => {
								uni.navigateTo({
									url: '../outputbodylist/outputbodylist?hid='+this.baseData.HeadId
								})
							}, 1000)

						} else {

							uni.showToast({
								title: `提交失败`,
								icon:'error',
							})
						}
					})

				}).catch(err => {
					console.log('err', err);
				})
			},
			onNavigationBarButtonTap() {
				this.submit('baseForm');
			},
		}
	}
</script>

<style>

</style>
